function [SVMParams]=CrossValidate(experiment_Index,tabledGroups, colNames, runParams)

kernalProps=DefaultKernalParameters();
kernalProps.nbclass =2;


analytes = unique(tabledGroups(:,1));
idx = find(tabledGroups(:,1)==analytes(2));
idxIDX=randperm(length(idx),400);
idx1=idx(idxIDX);

idx = find(tabledGroups(:,1)==analytes(3));
idxIDX=randperm(length(idx),400);
idx2=idx(idxIDX);

idxTr= [idx1(1:200)' idx2(1:200)'];
idxTe= [idx1(201:400)' idx2(201:400)'];

Training=tabledGroups(idxTr,:);
Testing=tabledGroups(idxTe,:);


Labels =[ones([1 200])*1 ones([1 200])*2]';

%cycle through the parameters to get the best SVM parameters
maxTraining = 0;
for C=.01:.1:.3
    for gamma=.5:.6:3
        disp('----------------------------------');
        kernalProps.kerneloption=[C gamma];
        [ allPeaksSVM, trainingAccuracy]=  CreateMultiClass(Training,Labels, kernalProps);
        disp(trainingAccuracy);
        predictedGroups  = svmmultivaloneagainstone(Testing,allPeaksSVM.xsup,allPeaksSVM.w,allPeaksSVM.b,allPeaksSVM.nbsv,allPeaksSVM.kernel,allPeaksSVM.kerneloption);
        testAccuracy = length(find(predictedGroups ==Labels))/length(Labels)*100;
        disp(testAccuracy);
        dist =1/ abs(testAccuracy-85);
        if dist>maxTraining
            maxTraining=dist;
            maxC=C;
            maxGamma=gamma;
        end
    end
end
kernalProps.kerneloption=[maxC maxGamma];
SVMParams=kernalProps;

% sql =['insert into SVM_Parameters ' ...
%     '(SVM_Experiment_Index, SVM_role, SVM_xsup ,SVM_alpha , SVM_rho, SVM_kernal, SVM_kernaloption, SVM_threshold , SVM_colNames) '...
%     'VALUES (' ...
%     num2str(experiment_Index) ',''' sprintf('%f3,',SVMParams.xsup) ''',''DefaultSVM'',''' sprintf('%f3,',SVMParams.alpha) ''',' ...
%     num2str(SVMParams.rho) ',''' SVMParams.kernel ''',''' sprintf('%f3,',SVMParams.kerneloption) ''',' ...
%     num2str(SVMParams.threshold) ',''' sprintf('%s,', colNames{ SVMParams.ColNames}) ''');'];
% 
% exec(conn,sql);
end